var Nav = require('../models/nav.js');
/*
 * GET home page.
 */

exports.index = function(req, res) {
	res.render('index', {});
};

var httpHelper = require('../models/httpHelper');
exports.hello=function(req,res){
	res.end("hello,world!");
};
exports.api = function(req, res) {
	var path = req.query.path;
	var method = req.query.method;
	var data = req.query.data;
	var times = req.query.times;
	var remoteAction = req.query.remoteAction;
	var URL = require('url');
	var url = URL.parse(path);
	if (times == "") {
		times = 1;
	}
	if (times == 1) {
		httpHelper.find(req, function(data) {
			// res.render('ruleConfig.html',{user:data});
			//res.contentType('json');
			res.write(data);
			res.end();
		}, url.hostname, url.port, url.path, method, data);
	} else {
		var c = 0;
		for (var i = 0; i < times; i++) {
			if (remoteAction) {
				httpHelper.find(req, function(data) {
					c++;
					if (c >= times) {
						// res.contentType('json');
						res.write(data);
						res.end();
					}
				}, url.hostname, url.port, url.path, method, data);
			} else {
				res.end();
			}
		}
	}
};